use actix_web::{App, HttpServer, middleware::Logger, web};
use naz_registry::{
    models::ServiceStorage,
    utils::print_logo,
    views::{view_get_all, view_query, view_register, view_unregister},
};

const PORT: u16 = 8081;

#[actix_web::main]
async fn main() -> std::io::Result<()> {
    unsafe {
        std::env::set_var("RUST_LOG", "actix_web=trace");
    };

    env_logger::init();
    let storage = web::Data::new(ServiceStorage::default());
    print_logo();
    HttpServer::new(move || {
        App::new()
            .app_data(storage.clone())
            .wrap(Logger::default())
            .service(
                web::scope("/api/v1/registry")
                    .service(view_register)
                    .service(view_query)
                    .service(view_unregister)
                    .service(view_get_all),
            )
    })
    .bind(("0.0.0.0", PORT))?
    .run()
    .await
}
